//
//detaliListTView
//listArray
//  AnnounceNumViewController.m
//  CaiPiao
//
//  Created by apple on 2018/5/16.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "AnnounceNumViewController.h"
#import "AnnounceNmuberCell.h"


@interface AnnounceNumViewController ()

@property (weak, nonatomic) IBOutlet UITableView *detaliListTView;


@property(nonatomic,retain)NSArray* listArray;

@end

@implementation AnnounceNumViewController{

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = [NSString stringWithFormat:@"%@开奖历史",[LotteryManager sharedManager].currentLotteryName];
    [self.detaliListTView registerNib:[UINib nibWithNibName:@"AnnounceNum" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AnnounceNmuberCell"];
    __weak typeof(self)weakSelf = self;
    [[LotteryManager sharedManager] getListWithLotteryID:[LotteryManager sharedManager].currentLotteryID andActionID:@"602" andCallBack:^(BOOL load, NSDictionary *resObj) {
        if (load) {
            weakSelf.listArray = resObj[@"data"];
            [weakSelf reloadAction];
        }
    }];
}

-(void)reloadAction{
    [self.detaliListTView reloadData];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.listArray count];
}


//    Amount = 39;
//    EndTime = "2018/05/15";
//    ID = 774132;
//    Money = "5,382,270";
//    Name = 2018055;
//    QuickFlag = 0;
//    TotalMoney = "921,156,717";
//    WinNumber = "07 09 10 12 22 26+07";
//    WinSum = 0;
//    WinType = "";



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    AnnounceNmuberCell* cell = [tableView dequeueReusableCellWithIdentifier:@"AnnounceNmuberCell"];
    NSDictionary* dic = self.listArray[indexPath.row];

    if ([self checkName]) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    cell.dateLabel.text = [NSString stringWithFormat:@"%@期 %@",dic[@"Name"],[dic[@"EndTime"] stringByReplacingOccurrencesOfString:@"/" withString:@"-"]];
    [cell setWinNumWith:dic[@"WinNumber"]];
    return cell;
}

-(BOOL)checkName{
    if ([[LotteryManager sharedManager].currentLotteryName isEqualToString:@"福彩3D"])
        return YES;
    if ([[LotteryManager sharedManager].currentLotteryName isEqualToString:@"排列3"])
        return YES;
    if ([[LotteryManager sharedManager].currentLotteryName isEqualToString:@"双色球"])
        return YES;
    if ([[LotteryManager sharedManager].currentLotteryName isEqualToString:@"大乐透"])
        return YES;
    if ([[LotteryManager sharedManager].currentLotteryName isEqualToString:@"胜负彩"])
        return YES;
    return NO;
}

//numberSegue
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary* dic = self.listArray[indexPath.row];
    [LotteryManager sharedManager].currentDetailID = dic[@"ID"];
    if ([self checkName]) {
        if ([[LotteryManager sharedManager].currentLotteryName isEqualToString:@"福彩3D"]){
            [self performSegueWithIdentifier:@"FCPLSDetailSegue" sender:nil];
        }
        if ([[LotteryManager sharedManager].currentLotteryName isEqualToString:@"排列3"]){
            [self performSegueWithIdentifier:@"FCPLSDetailSegue" sender:nil];
        }
            
        if ([[LotteryManager sharedManager].currentLotteryName isEqualToString:@"双色球"]){
            [self performSegueWithIdentifier:@"SSCDetailSegue" sender:nil];
        }
        if ([[LotteryManager sharedManager].currentLotteryName isEqualToString:@"大乐透"]){
            [self performSegueWithIdentifier:@"DLTDetailSegue" sender:nil];
        }
        if ([[LotteryManager sharedManager].currentLotteryName isEqualToString:@"胜负彩"]){
            [self performSegueWithIdentifier:@"SFCDetailSegue" sender:nil];
        }
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
